package com.sgb.kjwl.view.ui.adapter.self;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.link.entity.InvoiceManagementEntity;
import com.swgk.core.util.UiUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class InvoiceManagementAdapter extends BaseRecycleAdapter<InvoiceManagementEntity> {

    private onEditClickListener editClickListener;
    private TextView appCompatRadioButton;

    public void setonEditClick(onEditClickListener editClickListener) {
        this.editClickListener = editClickListener;
    }

    public interface onEditClickListener {
        void onEditClick(InvoiceManagementEntity data);

        void onDelClick(String id);

        void isCheck(boolean isCheck, int position);
    }


    public InvoiceManagementAdapter(Context context, List<InvoiceManagementEntity> datas) {
        super(context, R.layout.item_invoice_management, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, InvoiceManagementEntity data) {
        holder.setBinding(BR.viewModel, data);
//        TagTextView tvDetail = holder.itemView.findViewById(R.id.tv_detail);
        appCompatRadioButton = holder.itemView.findViewById(R.id.radio_is_def);
//        List<String> tags = new ArrayList<>();
        if (data.getIsDefault() == 1) {
//            tags.add("默认");
            appCompatRadioButton.setText("默认");
            appCompatRadioButton.setTextColor(UiUtil.getColor(R.color.new_blue));
            appCompatRadioButton.setBackground(context.getResources().getDrawable(R.drawable.shape_stroke_5));
        } else {
            appCompatRadioButton.setText("设为默认");
            appCompatRadioButton.setBackground(context.getResources().getDrawable(R.drawable.shape_stroke_5_white));
            appCompatRadioButton.setTextColor(UiUtil.getColor(R.color.color_666666));
        }
//        tvDetail.setContentAndTag(data.getAddress(), tags);


        holder.itemView.findViewById(R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editClickListener.onEditClick(data);
            }
        });

        holder.itemView.findViewById(R.id.tv_del).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editClickListener.onDelClick(data.getId());
            }
        });

        appCompatRadioButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (data.getIsDefault() == 1) {

                } else {
                    editClickListener.isCheck(true, holder.getPosition() - 1);
                }
            }
        });
    }
}
